# import asyncio
# from pyppeteer import launch
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QFileDialog
# from PyQt5 import QtGui
#
# # def openimage(self):
#     # imgName, imgType = QFileDialog.getOpenFileName(self, "打开图片", "", "*.jpg;;*.png;;All Files(*)")
#     # jpg = QtGui.QPixmap(imgName).scaled(self.label.width(), self.label.height())
#     # self.label.setPixmap(jpg)
#
#
# app = QApplication(sys.argv)
# window = QWidget()
# window.resize(650, 650)  # 窗口尺寸
# window.move(650, 300) # 窗口坐标
# window.setWindowTitle('销量排行')
# window.show()
#
#
#
#
#
# #
# # async def main():
# #     browser = await launch({'headless': T, 'args': ['--no-sandbox'], })
# #     page = await browser.newPage()
# #     await page.goto('https://www.baidu.com/')
# #
# #
# #
# #     await page.close()
# #     await browser.close()
# #
# # asyncio.get_event_loop().run_until_complete(main())
#
# # sys.exit(app.exec_())

import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class filedialogdemo(QWidget):

    def __init__(self, parent=None):
        super(filedialogdemo, self).__init__(parent)
        layout = QVBoxLayout()

        self.btn = QPushButton()
        self.btn.clicked.connect(self.loadFile)
        self.btn.setText("从文件中获取照片")
        layout.addWidget(self.btn)

        self.label = QLabel()
        layout.addWidget(self.label)

        self.btn_2 = QPushButton()
        self.btn_2.clicked.connect(self.load_text)
        self.btn_2.setText("加载电脑文本文件")
        layout.addWidget(self.btn_2)

        self.content = QTextEdit()
        layout.addWidget(self.content)
        self.setWindowTitle("测试")

        self.setLayout(layout)

    def loadFile(self):
        print("load--file")
        fname, _ = QFileDialog.getOpenFileName(self, '选择图片', 'c:\\', 'Image files(*.jpg *.gif *.png)')
        self.label.setPixmap(QPixmap(fname))

    def load_text(self):
        print("load--text")
        dlg = QFileDialog()
        dlg.setFileMode(QFileDialog.AnyFile)
        dlg.setFilter(QDir.Files)
        if dlg.exec_():
            filenames = dlg.selectedFiles()
            f = open(filenames[0], 'r')
            with f:
                data = f.read()
                self.content.setText(data)

if __name__ == '__main__':
    app = QApplication(sys.argv)

    fileload =  filedialogdemo()
    fileload.show()
    sys.exit(app.exec_())